package cn.jofei.common.util;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;

/**
 * @author bao
 * @version my-web v1.0
 * @description 对象工具类
 * @date 2022/2/22 16:30
 */
public class Utils {

    private Utils() {
        throw new AssertionError("ObjUtils cannot be instantiated!");
    }

    /**
     * 判断空
     *
     * @param pObj
     * @return
     */
    public static boolean isNull(Object pObj) {
        if (pObj == null) {
            return true;
        } else {
            if (pObj instanceof String) {
                if (((String) pObj).length() == 0) {
                    return true;
                }
            } else if (pObj instanceof Collection) {
                if (((Collection) pObj).size() == 0) {
                    return true;
                }
            } else if (pObj instanceof Map && ((Map) pObj).size() == 0) {
                return true;
            }
            return false;
        }
    }

    /**
     * 判断非空
     *
     * @param pObj
     * @return
     */
    public static boolean nonNull(Object pObj) {
        return !isNull(pObj);
    }

    public static boolean safeClose(Closeable cb) {
        if (null != cb) {
            try {
                cb.close();
            } catch (IOException var2) {
                return false;
            }
        }
        return true;
    }
}